﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UserGUI : MonoBehaviour
{
    private IUserAction action;
    private int highScore = 0;
    private bool startStatus = false;
    private string flyMode = "Kinematics";
    public int round = 1;

    GUIStyle buttonStyle;
    GUIStyle textStyle;
    GUIStyle titleStyle;

    void Start()
    {
        action = SSDirector.getInstance().currentSceneController as IUserAction;
        
        buttonStyle = new GUIStyle("button");
        buttonStyle.fontSize = 15;
        textStyle = new GUIStyle();
        textStyle.fontSize = 20;
        titleStyle = new GUIStyle();
        titleStyle.fontSize = 30;
    }

    private void OnGUI()
    {
        if (startStatus)
        {
            if (Input.GetButtonDown("Fire1"))
            {

                Vector3 mp = Input.mousePosition;
                action.Hit(mp);
            }
            GUI.Label(new Rect(10, 5, 200, 50), "Score:", textStyle);
            GUI.Label(new Rect(80, 5, 200, 50), action.GetScore().ToString(), textStyle);

            GUI.Label(new Rect(Screen.width - 120, 5, 50, 50), "Round:", textStyle);
            GUI.Label(new Rect(Screen.width - 40, 5, 50, 50), round.ToString(), textStyle);

            if (round > 3)
            {
                highScore = highScore > action.GetScore() ? highScore : action.GetScore();
                GUI.Label(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 100, 100, 100), "Game Over!", titleStyle);
                GUI.Label(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 50, 50, 50), "High Score:", textStyle);
                GUI.Label(new Rect(Screen.width / 2 + 50, Screen.height / 2 - 50, 50, 50), highScore.ToString(), textStyle);
                if(GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 10, 100, 50), "Restart", buttonStyle))
                {
                    round = 1;
                    action.Restart();
                    return;
                }
                if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 50, 100, 50), "Kinematics", buttonStyle))
                {
                    action.SetFlyMode(false);
                    flyMode = "Kinematics";
                }
                if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 110, 100, 50), "Physics", buttonStyle))
                {
                    action.SetFlyMode(true);
                    flyMode = "Physics";
                }
                action.GameOver();
            }
        }
        else
        {
            GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 100, 100, 100), "Hit UFO", titleStyle);
            GUI.Label(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 50, 400, 100), "点击消灭飞碟，在三轮飞碟入侵中取得最高分！", textStyle);
            if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 10, 100, 50), "Start", buttonStyle))
            {
                startStatus = true;
                action.StartGame();
            }

            if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 50, 100, 50), "Kinematics", buttonStyle))
            {
                action.SetFlyMode(false);
                flyMode = "Kinematics";
            }
            if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 110, 100, 50), "Physics", buttonStyle))
            {
                action.SetFlyMode(true);
                flyMode = "Physics";
            }
        }

        GUI.Label(new Rect(Screen.width / 2 - 100, 5, 50, 50), "Fly Mode: ", textStyle);
        GUI.Label(new Rect(Screen.width / 2, 5, 50, 50), flyMode, textStyle);
    }
    public void nextRound()
    {
        if (round <= 3)
        {
            round++;
        }
    }
}